//
//  ClassManageViewController.m
//  IpadTestB
//
//  Created by edianzu on 2017/7/3.
//  Copyright © 2017年 ruilai. All rights reserved.
//

#import "ClassManageViewController.h"
#import "ClassManageCell.h"
#import "AddClassOrCNView.h"
@interface ClassManageViewController ()<UITableViewDelegate,UITableViewDataSource,UITextFieldDelegate>
@property(nonatomic,strong)BaseAlertView * alertView;
@property(nonatomic,strong)AddClassOrCNView * addClassView;
@property(nonatomic,strong)AddClassOrCNView * changeNameView;
@property (nonatomic,strong)NSMutableDictionary * allDataDictionary;
@property(nonatomic,copy)NSIndexPath * indexPath;
@end

@implementation ClassManageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加键盘监听事件
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillShoww:) name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(keyboardWillHidee:) name:UIKeyboardWillHideNotification object:nil];
    // Do any additional setup after loading the view.
    self.title = @"班级管理";
    self.view.backgroundColor = UIColorFromRGB(241, 246, 248);
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSFontAttributeName:[UIFont boldSystemFontOfSize:23*AutoScaleHorizontal],
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    ////////////////左按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBtn.frame = CGRectMake(0, 0, 35,35);
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"navBack"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(leftBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * leftBarBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItem.width = 15;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.leftBarButtonItems = @[spaceItem,leftBarBtn];
    
    //创建右边按钮
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 140,35);
        rightBtn.layer.cornerRadius =10;
    rightBtn.backgroundColor = [UIColor whiteColor];
    //    [rightBtn setImage:[UIImage imageNamed:@"navRightBtn"] forState:UIControlStateNormal];
    [rightBtn setTitle:@"十  添加班级" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = [UIFont systemFontOfSize:20*AutoScaleHorizontal];
    [rightBtn setTitleColor:UIColorFromRGB(26, 167, 157) forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(rightBarBtnClicked) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem * rightBarBtn = [[UIBarButtonItem alloc]initWithCustomView:rightBtn];;
    //创建UIBarButtonSystemItemFixedSpace
    UIBarButtonItem * spaceItemm = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    //将宽度设为负值
    spaceItemm.width = -5;
    //将两个BarButtonItem都返回给NavigationItem
    self.navigationItem.rightBarButtonItems = @[spaceItemm,rightBarBtn];
    [self getData];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

-(void)getData{
    self.schoolNameArr = [[NSMutableArray alloc]initWithCapacity:0];
    
    
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    //获取全部数据
    NSString* str = [user objectForKey:@"AllData"];
    //    NSLog(@"eee===%@",str);
    NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
    _allDataDictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    NSMutableArray * allClassArr  = [[NSMutableArray alloc]init];
    allClassArr = [_allDataDictionary objectForKey:@"ClassList"];
    for (NSDictionary * dic in allClassArr) {
        ClassModel * mod = [ClassModel modelWithDictionary:dic];
        [self.schoolNameArr addObject:mod];
    }
    [self createUI];
    
}

-(void)createUI{
    self.myTableView = [[UITableView alloc]init];
    self.myTableView.backgroundColor =UIColorFromRGB(241, 244, 248);
    self.myTableView.delegate =self;
    self.myTableView.dataSource =self;
    self.myTableView.showsVerticalScrollIndicator =NO;
    //修改索引颜色
    self.myTableView.sectionIndexBackgroundColor = [UIColor clearColor];//修改右边索引的背景色
    self.myTableView.sectionIndexColor = UIColorFromRGB(26, 167, 157);//修改右边索引字体的颜色
    //    self.myTableView.sectionIndexTrackingBackgroundColor = [UIColor orangeColor];//修改右边索引点击时候的背景色
    //无分割线
        self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //多余的CELL 隐藏
    self.myTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.myTableView registerClass:[ClassManageCell class] forCellReuseIdentifier:@"ClassManageCell"];
    [self.view addSubview:self.myTableView];
    [self.myTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.view.mas_left).with.offset(50*AutoScaleHorizontal);
        make.right.mas_equalTo(self.view.mas_right).with.offset(-50*AutoScaleHorizontal);
        make.top.mas_equalTo(self.view.mas_top).with.offset(30*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT-100*AutoScaleHorizontal));
    }];

}

#pragma mark tableViewDelegate
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100*AutoScaleVertical;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.schoolNameArr.count;
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ClassManageCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ClassManageCell"];
    if (cell ==nil) {
        cell = [[ClassManageCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: @"ClassManageCell"] ;
    }
    __weak typeof(self) weak_self = self;
    //修改名字
    cell.callChange = ^( NSIndexPath * indexp) {
        [weak_self ChangeCLassNameWith:indexp];
    };
    //删除班级
    cell.callDelete = ^( NSIndexPath * indexp) {
        
//        [self stillHavePerson];
        
        ClassModel * mod = self.schoolNameArr[indexPath.row];
        NSMutableArray * testArray = [NSMutableArray arrayWithArray: [_allDataDictionary objectForKey:@"ChildList"]];
        NSInteger joinProNumber = 0;
        //CLASSID等于ID ，说明班里有人
        for (NSDictionary * dict in testArray) {
            if ([[dict objectForKey:@"ClassId"]isEqual:mod.Id]) {
                joinProNumber += 1;
            }
        }
        if (joinProNumber == 0) {
            [weak_self creatDeleteViewWithIndex:indexp];
        }else{
            [weak_self stillHavePerson];//有人时，创建还有孩子窗口
        }
        
    };
    [cell relayoutCellWithModel:self.schoolNameArr[indexPath.row] andIndex:indexPath];
    return cell;
}

#pragma mark  修改名称
-(void)ChangeCLassNameWith:(NSIndexPath*)indexpath{
    self.indexPath = [[NSIndexPath alloc]init];
    self.indexPath = indexpath;
    ClassModel * model = self.schoolNameArr[indexpath.row];
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.changeNameView = [[AddClassOrCNView alloc]init];
    self.changeNameView.remindLabel.text = @"修改名称";
    self.changeNameView.infoTextField.text = model.Name;
    self.changeNameView.infoTextField.delegate = self;
    [window addSubview:self.changeNameView];
    [self.changeNameView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(window.mas_centerX);
        make.centerY.mas_equalTo(window.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 250*AutoScaleVertical));
    }];
    [self.changeNameView.sureBtn addTarget:self action:@selector(changeSureWithindex:) forControlEvents:UIControlEventTouchUpInside];
    [self.changeNameView.cancelBtn addTarget:self action:@selector(changeCancel) forControlEvents:UIControlEventTouchUpInside];
}
//确定修改
-(void)changeSureWithindex:(NSIndexPath*)indexPath{
    indexPath = self.indexPath;
    
    
    if (self.changeNameView.infoTextField.text.length == 0) {
        [self showMessage:@"班级名不能为空"];
    }else{
    
            ClassModel* model = self.schoolNameArr[indexPath.row];
            model.Name = self.changeNameView.infoTextField.text;
    //        NSLog(@"x");
            [self.schoolNameArr replaceObjectAtIndex:indexPath.row withObject:model];
    //更新数据源
    NSUserDefaults * user =[NSUserDefaults standardUserDefaults];
    NSMutableArray * arr = [_allDataDictionary objectForKey:@"ClassList"];
    NSMutableDictionary * dic = arr[indexPath.row];
        if (![[dic objectForKey:@"Name"]isEqualToString:self.changeNameView.infoTextField.text]) {
            [dic setObject:@"1" forKey:@"1900V"];
        }
    [dic removeObjectForKey:@"Name"];
    [dic setObject:self.changeNameView.infoTextField.text forKey:@"Name"];
    [arr replaceObjectAtIndex:indexPath.row withObject:dic];
    
    [_allDataDictionary removeObjectForKey:@"ClassList"];
    [_allDataDictionary setObject:arr forKey:@"ClassList"];
    NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
    NSString * allStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    //
    [user removeObjectForKey:@"AllData"];
    [user setObject:allStr forKey:@"AllData"];
    
    [user synchronize];
        [_backView removeFromSuperview];
        [self.changeNameView removeFromSuperview];
        [self.myTableView reloadData];
    }
    
    
}
-(void)changeCancel{
    [_backView removeFromSuperview];
    [self.changeNameView removeFromSuperview];
}
#pragma mark  删除班级
//还有孩子，不让删
-(void)stillHavePerson{
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    _alertView = [[BaseAlertView alloc]init];
    _alertView.infomationLabel.text = @"该班级内仍有学员,无法删除该班级";
    [window addSubview:_alertView];
    [_alertView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(window.mas_centerX);
        make.centerY.mas_equalTo(window.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 250*AutoScaleVertical));
    }];
    [_alertView.yesBtn removeFromSuperview];
    [_alertView.noBtn removeFromSuperview];
    UIButton * iknowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [iknowBtn addTarget:self action:@selector(pressIknow) forControlEvents:UIControlEventTouchUpInside];
    [iknowBtn setTitle:@"我知道了" forState:UIControlStateNormal];
    iknowBtn.backgroundColor = UIColorFromRGB(26, 167, 157);
    iknowBtn.layer.cornerRadius = 10;
    iknowBtn.layer.masksToBounds = YES;
    [iknowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.alertView addSubview:iknowBtn];
    [iknowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.alertView.mas_centerX);
        make.bottom.mas_equalTo(self.alertView.mas_bottom).with.offset(-40*AutoScaleVertical);
        make.size.mas_equalTo(CGSizeMake(100*AutoScaleHorizontal, 30*AutoScaleVertical));
    }];
    
}
-(void)pressIknow{
    [_backView removeFromSuperview];
    [self.alertView removeFromSuperview];
}

//没孩子了 可以删
-(void)creatDeleteViewWithIndex:(NSIndexPath*)indexpath{
    self.indexPath = indexpath;
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];

    _alertView = [[BaseAlertView alloc]init];
    _alertView.infomationLabel.text = @"是否删除该班级?";
    [window addSubview:_alertView];
        [_alertView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(window.mas_centerX);
            make.centerY.mas_equalTo(window.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 250*AutoScaleVertical));
        }];
        [_alertView.yesBtn addTarget:self action:@selector(pressAlertYesWithindex:) forControlEvents:UIControlEventTouchUpInside];
        [_alertView.noBtn addTarget:self action:@selector(pressAlertNo) forControlEvents:UIControlEventTouchUpInside];
}
-(void)pressAlertYesWithindex:(NSIndexPath*)indexpath{
    NSLog(@"确定删除");
    indexpath = self.indexPath;
    ClassModel * mod = self.schoolNameArr[indexpath.row];
    for (ClassModel * model in self.schoolNameArr.reverseObjectEnumerator) {
        if (model == mod) {
            [self.schoolNameArr removeObject:model];
        }
    }
    //更新数据源
    NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
    NSMutableArray * arr = [_allDataDictionary objectForKey:@"ClassList"];
    NSMutableDictionary * dic = arr[indexpath.row];
    [arr removeObject:dic];
    
    [_allDataDictionary removeObjectForKey:@"ClassList"];
    [_allDataDictionary setObject:arr forKey:@"ClassList"];
    NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
    NSString * allStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
    //
    [user removeObjectForKey:@"AllData"];
    [user setObject:allStr forKey:@"AllData"];
    
    [user synchronize];
    
    if (mod.Id>0) {
        
        if ([user objectForKey:@"deleteClassArray"] !=nil) {
            
        
        NSString* str = [user objectForKey:@"deleteClassArray"];
        //    NSLog(@"eee===%@",str);
        NSData *jsonData = [str dataUsingEncoding:NSUTF8StringEncoding];
        NSMutableDictionary * dict = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
        NSMutableArray * allClassArr  = [[NSMutableArray alloc]init];
        allClassArr = [dict objectForKey:@"deleteClassArray"];
        [allClassArr addObject:mod.Id];
        
        [dict removeObjectForKey:@"deleteClassArray"];
        [dict setObject:allClassArr forKey:@"deleteClassArray"];
        NSData * data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
        NSString * allStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        [user removeObjectForKey:@"deleteClassArray"];
        [user setObject:allStr forKey:@"deleteClassArray"];
        [user synchronize];
        
        }else{
            NSMutableArray * DCA = [[NSMutableArray alloc]init];
            [DCA addObject:mod.Id];
            NSMutableDictionary * dcd = [[NSMutableDictionary alloc]init];
            [dcd setObject:DCA forKey:@"deleteClassArray"];
            NSData * data = [NSJSONSerialization dataWithJSONObject:dcd options:NSJSONWritingPrettyPrinted error:nil];
            NSString* deleteChild = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
            [user setObject:deleteChild forKey:@"deleteClassArray"];
            [user synchronize];
        }
    }
    [_backView removeFromSuperview];
    [self.alertView removeFromSuperview];
    [self.myTableView reloadData];
    

}
-(void)pressAlertNo{
    NSLog(@"取消删除");
    [_backView removeFromSuperview];
    [self.alertView removeFromSuperview];
}
#pragma mark 左右导航栏按钮方法
-(void)leftBarBtnClicked{
    NSLog(@"左按钮");
    [self.navigationController popViewControllerAnimated:YES];
}
//添加班级
-(void)rightBarBtnClicked{
    NSLog(@"添加ING");
    //蒙版
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    _backView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _backView.backgroundColor = [UIColor blackColor];
    _backView.alpha = 0.52;
    [window addSubview:_backView];
    
    self.addClassView = [[AddClassOrCNView alloc]init];
    self.addClassView.remindLabel.text = @"添加班级";
    self.addClassView.infoTextField.placeholder = @"请输入班级名称";
    [window addSubview:self.addClassView];
    [self.addClassView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(window.mas_centerX);
        make.centerY.mas_equalTo(window.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(500*AutoScaleHorizontal, 250*AutoScaleVertical));
    }];
    [self.addClassView.sureBtn addTarget:self action:@selector(AddSureWithindex:) forControlEvents:UIControlEventTouchUpInside];
    [self.addClassView.cancelBtn addTarget:self action:@selector(AddCancel) forControlEvents:UIControlEventTouchUpInside];
}
//确认添加
-(void)AddSureWithindex:(NSIndexPath*)indexPath{
    if (self.addClassView.infoTextField.text.length ==0) {
        [self showMessage:@"请输入新班级名称"];
    }else{
        ClassModel * mod = [[ClassModel alloc]init];
        mod.Name = self.addClassView.infoTextField.text;
        [self.schoolNameArr addObject:mod];
        ClassModel * unClassed = [[ClassModel alloc]init];
        for (ClassModel* dict in self.schoolNameArr.reverseObjectEnumerator) {
            if ([dict.Name isEqualToString:@"未分班"]) {
                unClassed = dict;
                [self.schoolNameArr removeObject:dict];
                
            }
        }
        [self.schoolNameArr addObject:unClassed];
        
        //获取当前时间
        NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
        NSDate *datenow = [NSDate date];
        NSString *currentTimeString = [formatter stringFromDate:datenow];
        NSString * currentTime = [currentTimeString substringWithRange:NSMakeRange(0, 10)];
        
        
        //更新数据源
        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];
        NSMutableArray * arr = [_allDataDictionary objectForKey:@"ClassList"];
        NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
        [dic setObject:self.addClassView.infoTextField.text forKey:@"Name"];
        NSInteger newClassId = [[user objectForKey:@"CreatClassId"]integerValue]-1;
        NSNumber * ClassId = [NSNumber numberWithInt:newClassId];
        [user removeObjectForKey:@"CreatClassId"];
        [user setObject:ClassId forKey:@"CreatClassId"];
        [dic setObject:ClassId forKey:@"Id"];
        [dic setObject:currentTime forKey:@"CreateTime"];
        [dic setObject:[user objectForKey:@"AgencyId"] forKey:@"ServiceUnitId"];

        [arr addObject:dic];
        NSMutableDictionary *unClassed1 = [[NSMutableDictionary alloc]init];
        for (NSMutableDictionary*dict in arr.reverseObjectEnumerator) {
            if ([[dict objectForKey:@"Name"]isEqualToString:@"未分班"]) {
                unClassed1 = dict;
                [arr removeObject:dict];
                
            }
        }
        [arr addObject:unClassed1];
        [_allDataDictionary removeObjectForKey:@"ClassList"];
        [_allDataDictionary setObject:arr forKey:@"ClassList"];
        NSData * data = [NSJSONSerialization dataWithJSONObject:_allDataDictionary options:NSJSONWritingPrettyPrinted error:nil];
        NSString * allStr = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
        //
        [user removeObjectForKey:@"AllData"];
        [user setObject:allStr forKey:@"AllData"];
        
        [user synchronize];
        [_backView removeFromSuperview];
        [self.addClassView removeFromSuperview];
        [self.myTableView reloadData];
    }
    
}
-(void)AddCancel{
    [_backView removeFromSuperview];
    [self.addClassView removeFromSuperview];
}

#pragma mark ---- 根据键盘高度将当前视图向上滚动同样高度
///键盘显示事件
- (void)keyboardWillShoww:(NSNotification *)notification {
    //获取键盘高度，在不同设备上，以及中英文下是不同的
    CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
    
    //计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
    CGFloat offset = kbHeight;
    
    // 取得键盘的动画时间，这样可以在视图上移的时候更连贯
    double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    
    //将视图上移计算好的偏移
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    if(offset > 0) {
        [UIView animateWithDuration:duration animations:^{
            window.frame = CGRectMake(0.0f, -85*AutoScaleVertical, window.frame.size.width, window.frame.size.height);
        }];
    }
}
#pragma mark ---- 当键盘消失后，视图需要恢复原状
///键盘消失事件
- (void)keyboardWillHidee:(NSNotification *)notify {
    // 键盘动画时间
    double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
    //视图下沉恢复原状
    UIWindow * window = [UIApplication sharedApplication].keyWindow;
    [UIView animateWithDuration:duration animations:^{
        window.frame = CGRectMake(0, 0, window.frame.size.width, window.frame.size.height);
    }];
}
// 释放
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillShowNotification object:nil];
    [[NSNotificationCenter defaultCenter]removeObserver:self name:UIKeyboardWillHideNotification object:nil];
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
